//
//  Controller16.swift
//  Swift30Days
//
//  Created by licheng ke on 2017/3/9.
//  Copyright © 2017年 licheng ke. All rights reserved.
//

import UIKit

//SlideMeun
class Controller16: UIViewController,
                    UITableViewDelegate,
                    UITableViewDataSource,
                    TransitionHandleDelegate
{

    var tableView : UITableView!
    let datas = PersonData.fakeDatas()
    let transitionHander = TransitionHandle()
    var changeBlock : ((String) -> ())?;
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .black;
        self.modalPresentationStyle = .custom;
        transitionHander.delegate = self;
        configUI();

    }

    func configUI(){
        tableView = UITableView(frame: self.view.bounds, style: .plain);
        tableView.register(UINib(nibName: "NewsCell", bundle: nil), forCellReuseIdentifier: "aaa");
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.rowHeight = 240;
        tableView.backgroundColor = .clear;
        view.addSubview(tableView);
        
        //navigation bar
        let barButtonItem = UIBarButtonItem(title: "🍔", style: .plain, target: self, action: #selector(transitionAction));
        self.navigationItem.rightBarButtonItem = barButtonItem;
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return datas.count * 2;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       let cell = tableView.dequeueReusableCell(withIdentifier: "aaa", for: indexPath) as! NewsCell;
        cell.data = datas[indexPath.row % datas.count];
        return cell;
    }
    
    func transitionAction(){
        let c = Controller15();
        //设置下一个界面的转场代理,这里到底是设置哪个controller？
        c.transitioningDelegate = transitionHander;
        c.callBack = {
            title in
            self.title = title
        }
        self.navigationController?.present(c, animated: true, completion: {
            print("aaa")
        });
        
    }
    
    func missAction(){
        self.dismiss(animated: true, completion: nil);
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    


}
